
<!DOCTYPE html>
<!--suppress ALL-->
<html xmlns:th="http://www.thymeleaf.org">
<!-- Head -->
<head>

    <title>注册</title>

    <!-- Meta-Tags -->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <!-- style CSS -->
    <link rel="stylesheet" href="../css/style1.css" type="text/css" media="all">

    <!-- fontawesome -->
    <link rel="stylesheet" href="../css/font-awesome.min.css" type="text/css" media="all">
    <script src="../js/jquery.js"></script>
    <script src="../layui/layui.js"></script>
<!--    &lt;!&ndash; google fonts 会导致延迟 &ndash;&gt;-->
<!--    <link href="//fonts.googleapis.com/css?family=Mukta:300,400,500" rel="stylesheet">-->

</head>
<!-- //Head -->

<!-- Body -->

<body>

    <section class="main">
        <div class="bottom-grid">
            <div class="logo">
                <h1> <a href="reg.html"> 注册 </a></h1>
            </div>
        </div>
        <!-- register -->
        <div class="w3lhny-register">
            <div class="iconhny">
               <span class="fa fa-user-plus"></span>
             </div>
            <form action ="#" method="post" class="register-form">
                <fieldset>
                    <div class="form">
                        <div class="form-row">
                            <span class="fa fa-book"></span>

                            <input type="text" class="form-text" placeholder="账号" id = "uAccount" required="">
                        </div>
                        <div class="form-row">
                            <span class="fa fa-user"></span>
                           
                            <input type="text" class="form-text" placeholder="姓名" id = "uName" required="">
                        </div>
                        <div class="form-row">
                            <span class="fa fa-envelope"></span>
                            
                            <input type="email" class="form-text" placeholder="邮箱" id = "uEmail" required="">
                        </div>
                        <div class="form-row">
                            <span class="fa fa-lock"></span>
                            
                            <input type="password" class="form-text" placeholder="密码" id = "uPassWord" required="">
                        </div>
                        <div class="form-row">
                                <span class="fa fa-lock"></span>

                                <input type="password" class="form-text" placeholder="再次确认密码" id = "confirmPwd" required="">
                        </div>
                        </div>
                        <div class="form-row button-login" >
                            <button type="button" class="btn btn-success" id="register">注册</button>
                            <select name="u_Power" style="height: 22px;padding-left: 10px;">
                                <option value="1" id="uPower">学生</option>
                                <option value="2" id="uPower">老师</option>
                            </select>
                        </div>
                </fieldset>
                </form>


                <!--<p class="already">Already have an account ? <a href="login.html">登录</a></p>-->
        </div>
        <!-- //register -->
        <div class="w3l-copyright">
            <p>© 2020 Workspace Sign Up Form. All rights reserved | Design by <a href="#">W3layouts</a>
            </p>
        </div>
    </section>

</body>
<!-- //Body -->

</html>
<script>

    //判断密码和确认密码是否一致
    $("#confirmPwd").blur(function () {
        //alert("以启用")
        var uPassWord = $("#uPassWord").val();
        var confirmPwd = $("#confirmPwd").val();
        //发起 ajax 请求
        var url = "/user/checkPwd";
        var param = {"uPassWord" : uPassWord, "confirmPwd" : confirmPwd};
        //发送密码之类的保密性高一点的用 post 请求
        $.post(url, param, function (data) {
            if(data.code == 200){
                layer.msg(data.msg);
            } else {
                layer.msg(data.msg);
            }
        }, "json");
    })


    //给注册 id = register 添加点击事件
    $("#register").click(function () {
        //alert("注册")
        //获取表单数据
        var uAccount = $("#uAccount").val();
        var uName = $("#uName").val();
        var uEmail = $("#uEmail").val();
        var uPassWord = $("#uPassWord").val();
        var confirmPwd = $("#confirmPwd").val();
        var uPower = $("#uPower").val();
        var url = "/user/doReg";
        var param = {"uAccount" : uAccount,"uName" : uName,"uEmail" : uEmail,"uPassWord" : uPassWord,
            "confirmPwd" : confirmPwd, "uPower" : uPower};
        $.post(url, param, function (data) {
            if(data.code == 200){
                layer.msg(data.msg)
                //一次性定时器，延迟一定时间
                var timeout = setTimeout(function () {
                    //跳转到登录
                    location.href="/toUserLogin";
                }, 1000);
            } else{
                layer.msg(data.msg)
            }
        }, "json");
    })

</script>